﻿/*
	Copyright (C) 2012 Bernardo van der Wal <bernardo@thebigb.nl>

	Permission is hereby granted, free of charge, to any person obtaining a copy of
	this software and associated documentation files (the "Software"), to deal in
	the Software without restriction, including without limitation the rights to
	use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
	of the Software, and to permit persons to whom the Software is furnished to do
	so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in all
	copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
	SOFTWARE.
*/
using System;

namespace TheBigB.JsonSerializerLite
{
	/// 
	/// Extensions interface for the JsonSerializer.
	/// 
	/// The IJsonSerializerExtension provides a skeleton for JsonSerializer extensions.
	/// When implemented you can add the extension using
	///		[JsonSerializer instance].Extenders += [your extension instance];
	///	
	/// If you wish to assign multiple types to a single extensions you can use the 
	///	RegisterExtension() method
	///		[JsonSerializer instance].Extenders.RegisterExtension([target type], [your extension instance]);
	///		[JsonSerializer instance].Extenders.RegisterExtension([next target type], [your extension instance]);
	///	

	/// <summary>
	/// Extensions interface for the JsonSerializer.
	/// </summary>
	public interface IJsonSerializerExtension
	{
		/// <summary>
		/// Should return the type implementing extension targets.
		/// </summary>
		/// <returns>Type of target</returns>
		Type GetTargetType();

		/// <summary>
		/// Should parse the provided input object and return the JSON representation.
		/// </summary>
		/// <param name="input">Object to parse</param>
		/// <param name="serializerInstance">Instance of the JsonSerializer class to allow recursive calling within the same scope</param>
		/// <returns>JSON representation of object</returns>
		string Serialize(object input, JsonSerializer serializerInstance);

		/// <summary>
		/// Should parse the provided JSON string and return a derserialized object instance
		/// </summary>
		/// <param name="input">JSON string to parse</param>
		/// <param name="targetType">Target type for the deserialized object</param>
		/// <param name="serializerInstance">Instance of the JsonSerializer class to allow recursive calling within the same scope</param>
		/// <returns>Deserialized object instance</returns>
		object Deserialize(string input, Type targetType, JsonSerializer serializerInstance);
	}
}
